package vg.modules.search.components;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;

import vg.modules.search.SearchPluginGlobals;

/**
 * This class realizes action(open in new tab or in current tab) in second panel.
 * @author tzolotuhin
 */
public class ActionModePanel {
	private final JPanel view;
	private final JRadioButton openInNewTabRadio, replaceTabRadio;
	/**
	 * Constructor.
	 */
	public ActionModePanel(final FBSecondPanel fbSecondPanel) {
		this.view = new JPanel(new GridLayout(2, 1));
		Border titled = BorderFactory.createTitledBorder("Action");
		this.view.setBorder(titled);

		this.openInNewTabRadio = new JRadioButton("Open in new tab");
		this.openInNewTabRadio.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fbSecondPanel.setActionMode(SearchPluginGlobals.DEF_ACTION_MODE_1);
			}
		});
		
		this.replaceTabRadio = new JRadioButton("Replace tab");
		this.replaceTabRadio.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fbSecondPanel.setActionMode(SearchPluginGlobals.DEF_ACTION_MODE_2);
			}
		});
		
		ButtonGroup group = new ButtonGroup();
		group.add(this.openInNewTabRadio);
		group.add(this.replaceTabRadio);
		this.openInNewTabRadio.setSelected(true);
		//package of interface
		this.view.add(this.openInNewTabRadio);
		this.view.add(this.replaceTabRadio);
	}
	public JPanel getView() {
		return(this.view);
	}
}
